home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 36 < prev    next >
Text File  |  1996-08-06  |  2KB  |  51 lines

  1. Path: informix.com!news
  2. From: Daniel Wood <dwood>
  3. Newsgroups: comp.std.c
  4. Subject: Undefined result vs. int's holding undefined values.
  5. Date: 5 Jan 1996 21:59:39 GMT
  6. Organization: Informix Software, Inc. Menlo Park, CA 94025
  7. Message-ID: <4ck70b$rd7@news.informix.com>
  8. NNTP-Posting-Host: dwood.informix.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1N (X11; I; SunOS 5.4 sun4m)
  13. X-URL: news:comp.std.c
  14.  
  15. THE TEST CASE, on SCO:
  16.  
  17. main() { f(-2147483647, 1879048192); }
  18.  
  19. f(int x, int y) {
  20.     int r;
  21.  
  22.     if ((r=(x-y)) > 0)
  23.         printf("1: r greater than 0\n");
  24.  
  25.     if (r > 0)
  26.         printf("2: r greater than 0\n");
  27. }
  28.  
  29. On SCO only the second print occurs.  The reason given to me is that ANSI
  30. states
  31. that the result of an overflowing/underflowing operation is undefined.  The
  32. implementation is free to do what it wants with the result.  This is fine
  33. with me, however int's, unlike floats, have NO undefined bit patterns and
  34. no matter what you do with the undefined result(Scramble the bits for all
  35. I care) once you store that something into an int variable that int
  36. is NOT undefined and allowed to exhibit volatile behavior.
  37.  
  38. Saying a result is undefined "IS NOT EQUAL TO" saying that a C int variable
  39. can actually hold an undefined value.  If you think the test case is running
  40. acceptably, as described above, then tell me the section of the standard that
  41. states or implies that an int variable can hold an undefined value.
  42.  
  43. Why say ye all?
  44.  
  45. -- 
  46. If you want a fancy saying then go find yourself a poet.
  47. If you want a bug cracked then you've come to the right place.
  48.  
  49. "The numbers speak to me" - 44 61 6E 20 57 6F 6F 64
  50.  
  51.